<!doctype html>
<%@ page import="com.mastercard.labs.Card"%>
<html class="no-js" lang="en">
<head>
<meta name="layout" content="common">
<style>
input[type="number"] {
	height: 30px;
}
</style>
<title>Manage Card</title>
</head>
<body id="body">
	<h2>Manage Card - <g:if test="${cardInstance?.id}">Update</g:if><g:else>Create</g:else></h2>
	<hr />
	<g:if test="${flash.message}">
		<div class="alert alert-success">
			<img src="${resource(dir:'images', file:'icon_successful.png') }" />&nbsp;&nbsp;${flash.message}
		</div>
	</g:if>
	<!-- 
	<g:hasErrors bean="${cardInstance}">
			<ul class="errors" role="alert">
				<g:eachError bean="${cardInstance}" var="error">
				<li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
				</g:eachError>
			</ul>
	</g:hasErrors>
	 -->
		<%--  
	<td>${cardInstance.bank?.name}</td>
						<td>${cardInstance.brand}</td>
						<td>${cardInstance.maskNumber}</td>
						<td>${cardInstance.holder}</td>
						<td>${cardInstance.expiry}</td>
						<td>${cardInstance.cvv2}</td>
						<td>${cardInstance.creditLimit}</td>
	--%>
	<div class="row>">
		<g:form method="POST" action="addCard">
			<g:hiddenField name="id" value="${cardInstance?.id}"/>
			<table class="table table-striped">
			  <thead>
        		<tr>
            	  <th>Card Detail</th>
        		</tr>
    	  	  </thead>
    		  <tbody>
				<tr>
					<td width="30%">Bank&nbsp;<font color="red">*</font></td>
					<td>
						<g:select name='bankid' value="${cardInstance?.bank?.id}" from='${banks}' optionKey="id" optionValue="name"> </g:select>
					</td>
				</tr>
				<tr>
					<td width="30%">Card Number&nbsp;<font color="red">*</font></td>
					<td>
					<g:textField name="number" maxlength="16" value="${fieldValue(bean:cardInstance,field:'number')}"/>
					<span class="errorMsg"><br/><g:fieldError bean="${cardInstance}" field="number" /></span>
					</td>
				</tr>
				<tr>
					<td width="30%">Brand&nbsp;<font color="red">*</font></td>
					<td>
					<g:textField name="brand"  maxlength="16" value="${fieldValue(bean:cardInstance,field:'brand')}"/>
					<span class="errorMsg"><br/><g:fieldError bean="${cardInstance}" field="brand" /></span>
					</td>
				</tr>
				<tr>
					<td width="30%">Holder Name&nbsp;</td>
					<td>
					<g:textField name="holder"  maxlength="16" value="${fieldValue(bean:cardInstance,field:'holder')}"/>
					<span class="errorMsg"><br/><g:fieldError bean="${cardInstance}" field="holder" /></span>
					</td>
				</tr>				
				<tr>
					<td width="30%">Expiry Date&nbsp;<font color="red">*</font></td>
					<td>
					<g:textField name="expiry"  maxlength="5" value="${fieldValue(bean:cardInstance,field:'expiry')}"/>
					<span class="errorMsg"><br/><g:fieldError bean="${cardInstance}" field="expiry" /></span>
					</td>
				</tr>
				<tr>
					<td width="30%">CVV2&nbsp;<font color="red">*</font></td>
					<td>
					<g:field type="number" name="cvv2"  maxlength="3" value="${fieldValue(bean:cardInstance,field:'cvv2')}"/>
					<span class="errorMsg"><br/><g:fieldError bean="${cardInstance}" field="cvv2" /></span>
					</td>
				</tr>
				<tr>
					<td width="30%">Credit Limit&nbsp;<font color="red">*</font></td>
					<td>
					<g:field type="number" name="creditLimit" maxlength="8" value="${cardInstance?.creditLimit}"/>
					<span class="errorMsg"><br/><g:fieldError bean="${cardInstance}" field="creditLimit" /></span>
					</td>
				</tr>
			  </tbody>
			</table>
			</br>
			<fieldset class="buttons">
					<g:actionSubmit class="btn btn-primary" action="saveCard" value="Submit" />
					<g:actionSubmit class="btn" action="show" value="Cancel" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
			</fieldset>
		</g:form>
	</div>
</body>
</html>
